package model.mobsMovers;

import java.util.Iterator;
import java.util.Observable;

import model.GameStatus;
import model.mobs.Mob;

public class LinearMover2D extends Observable implements Runnable{
	
	private GameStatus status;
	
	public LinearMover2D( GameStatus status ) {
		this.status = status;
	}	
	
	@Override
	public void run() {
		
		String ID;
		boolean isKillable;
		
		while (true) {
			
			Iterator<String> IDs = status.getMobsMapSet().iterator();
			
			while( IDs.hasNext() ){
				ID = IDs.next();
				Mob mob = status.getMob( ID );
				isKillable = mob.calculateNewCoordinate();
				if(isKillable){
					status.killMob(ID);
				}
			}
			
			setChanged();
			notifyObservers();
			
			try {
				Thread.sleep(10);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
